<template>
  <div>
    <h4>游戏咨询-热门推荐</h4>
    <ul class="list">
      <!-- <li v-for="item in hots" :key="item.id">{{ item.title }}</li> -->
      <!-- <router-link
        tag="li"
        v-for="item in hots"
        :key="item.id"
        v-bind:to="'/detail?id=' + item.id"
        >{{ item.title }}-{{ item.id }}</router-link
      > -->
      <!-- 通过 to 属性的对象取值模式，基于query对象定义，可以自动完成参数拼接 -->
      <!-- <router-link
        tag="li"
        v-for="item in hots"
        :key="item.id"
        :to="{
          path: '/detail',
          query: {
            id: item.id,
            name: '测试',
          },
        }"
        >{{ item.title }}-{{ item.id }}</router-link
      > -->
      <router-link
        tag="li"
        v-for="item in hots"
        :key="item.id"
        :to="{
          name: 'detail',
          query: {
            id: item.id,
            name: '测试',
          },
        }"
        >{{ item.title }}-{{ item.id }}</router-link
      >
    </ul>
    <hr />
    <ul class="list">
      <!-- <router-link
        tag="li"
        v-for="item in hots"
        :key="item.id"
        :to="`/detail/rest/${item.id}`"
        >{{ item.title }}-{{ item.id }}</router-link
      > -->

      <!-- rest参数模式下，routerLink 的to属性取值，不支持 对象的 path 规则，只能使用 name 规则 -->
      <router-link
        tag="li"
        v-for="item in hots"
        :key="item.id"
        :to="{
          name: 'rest',
          params: {
            id: item.id,
          },
        }"
        >{{ item.title }}-{{ item.id }}</router-link
      >
    </ul>
  </div>
</template>

<script>
// 见名知意
import $ from "jquery";
export default {
  data() {
    return {
      hots: [],
    };
  },
  methods: {
    loadHotGames() {
      $.get("http://139.196.82.122:8080/api/v1/index/hotpic", (result) => {
        // console.log(result);
        this.hots = result.data;
      });
    },
  },
  created() {
    this.loadHotGames();
  },
};
</script>

<style lang="scss" scoped>
.list {
  text-align: left;
  cursor: pointer;
}
</style>
